var carHttpUrl = 'http://114.55.228.245:8185/car/api/';
function req(data, url, cb) {
  console.info(data);
  console.info(carHttpUrl + url);
  wx.request({
    url: carHttpUrl + url,
    method: 'POST',
    data: data,
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    success: function (res) {
      return typeof cb == "function" && cb(res);
    },
    fail: function () {
      return typeof cb == "function" && cb(false)
    },
    complete: function () {
      //隐藏等待框
      // wx.hideLoading();
    }
  })
}
function reqUploadFile(data, url, filePath, cb) {
  wx.showLoading({
    title: '上传图片比对中',
  })
  wx.uploadFile({
    url: carHttpUrl + url,
    filePath: filePath,
    name: 'file',
    formData: data,
    success: function (res) {
      
      return typeof cb == "function" && cb(res);
    },
    fail: function () {
      return typeof cb == "function" && cb(false)
    },
  });
}

var rootDocment = 'https://wx.nbrobo.com/nkywx/transparent/miniUpload.html?content=';
var loginRootDocment = 'https://wx.nbrobo.com/nkywx/transparent/miniLogin.html?content=';
function reqForTiePian(data, cb) {
  data = JSON.stringify(data);
  console.info(rootDocment + data);
  wx.request({
    url: rootDocment + data,
    method: 'GET',
    header: { 'Content-Type': 'application/json' },
    success: function (res) {
      console.info(res);
      return typeof cb == "function" && cb(res);
    },
    fail: function () {
      return typeof cb == "function" && cb(false)
    },
    complete: function () {
      //隐藏等待框
      // wx.hideLoading();
    }
  })
}


function reqForTiePianLogin(data, cb) {
  data = JSON.stringify(data);
  console.info(data);
  wx.request({
    url: loginRootDocment + data,
    method: 'GET',
    header: { 'Content-Type': 'application/json' },
    success: function (res) {
      return typeof cb == "function" && cb(res.data)
    },
    fail: function () {
      return typeof cb == "function" && cb(false)
    },
    complete: function () {
      //隐藏等待框
      // wx.hideLoading();
    }
  })
}

module.exports = {
  req: req,
  reqUploadFile: reqUploadFile,
  reqForTiePian: reqForTiePian,
  reqForTiePianLogin: reqForTiePianLogin
}  